package com.wavehi.homework.second;

import com.wavehi.pojo.Person;

import java.lang.reflect.Method;
import java.sql.SQLOutput;

/**
 * @Author WaveHi
 * @Date 25/8/2021 下午 7:40
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description Second homework:Get methods.
 */
public class ReflectionDemo2 {

    public static void main(String[] args) throws NoSuchMethodException {

        //获取Class对象
        Class<Person> personClass = Person.class;

        //获取指定的公共方法
        Method publicMethod = personClass.getMethod("breathe");
        System.out.println("The public method is :'" + publicMethod);

        //获取所有的公共方法
        Method[] methods = personClass.getMethods();
        System.out.println("The all public methods :");
        for(Method method : methods) {

            System.out.println(method);

        }

        //获取指定的方法
        System.out.println("The declared method is :" + personClass.getDeclaredMethod("say", String.class));

        //获取所有方法
        Method[] declaredMethods = personClass.getDeclaredMethods();
        System.out.println("The declaredMethods :");
        for(Method declaredMethod : declaredMethods) {

            System.out.println(declaredMethod);

        }

    }

}

//小结：Method getMethod(String name,Class<?>... parameterTypes) 获取指定的公共的方法
//     Method[] getMethods() 获取所有公共方法组成的数组
//     Method getDeclaredMethod(String name,Class<?>... parameterTypes) 获取指定的直接方法
//     Method[] getDeclaredMethods() 获取所有直接方法组成的数组